import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { join, resolve } from 'path'
import { writeFileSync } from 'fs'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // createSvgIconsPlugin({
    //   // 指定要缓存的文件夹
    //   iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
    //   // 指定symbolId格式
    //   symbolId: 'icon-[dir]-[name]',
    //   customDomId: '__svg__icons__dom__',
    // })
    AutoImport({
      imports: ['vue', 'vue-router', 'vuex']
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          resolveIcons: true
        })
      ]
    })
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, './src'),
      'vue': 'vue/dist/vue.esm-bundler.js'
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          'primary-color': '#0066FF',
          'link-color': '#0066FF',
          'border-radius-base': '2px',
        },
        javascriptEnabled: true
      }
    }
  },
  server: {
    host: '0.0.0.0',
    // cors: true,
    port: 9000,
    headers: {
      'Access-Control-Allow-Origin': '*',
      // 'Access-Control-Request-Headers': 'authorization,content-type'
    },
    proxy: {
      '/api': {
        target: 'http://poc09.server.zzzc.qihoo.net:7781'
        // target: 'http://merger623.se.zzzc.qihoo.net'
        // target: 'http://kg.nrta.net.cn/'   // 广电线上环境
      }
    }
  },
  base: '/ai-app-demo-search/',
  build: {
    outDir: 'ai-app-demo-search'
  }
})
